import { useEffect } from "react";
import { useRoutes, useLocation, useNavigate } from "react-router-dom";
/*

*/
declare global {
  interface Window {
    [k: string]: any;
  }
}
export const useElement = (key: string, route: any) => {
  let element = useRoutes(route);
  let location = useLocation();
  let navigate = useNavigate();

  let token = sessionStorage.getItem(key);
  useEffect(() => {
    if (!token) {
        //没有token,跳转到login
        //如果访问的页面不是login 就跳转到login
        if (location.pathname !== "/login") {
            navigate('/login')
        }
    }
})



  return { element };
};
